/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.sanerzone.smscenter.gateway.web;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.google.common.collect.Maps;
import com.sanerzone.smscenter.account.entity.Account;
import com.sanerzone.smscenter.biz.cache.AccountCacheHelper;
import com.sanerzone.smscenter.biz.cache.GatewayCacheHelper;
import com.sanerzone.smscenter.biz.entity.DataEntity;
import com.sanerzone.smscenter.biz.entity.SmsGateway;
import com.sanerzone.smscenter.biz.entity.SmsSend;
import com.sanerzone.smscenter.biz.service.impl.SmsSendServiceImpl;
import com.sanerzone.smscenter.common.tools.JedisUtils;
import com.sanerzone.smscenter.gateway.base.GateWay;
import com.sanerzone.smscenter.gateway.http.HttpGatewayFactory;
import com.sanerzone.smscenter.gateway.http.handler.GateWayHttpAbstract;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 日报表Controller
 * @author zhukc
 * @version 2017-06-26
 */
@Controller
@RequestMapping(value = "/cache")
public class CacheController {

	@Autowired
	private SmsSendServiceImpl smsSendService;

	@RequestMapping(value = "/account")
	public String list(Account account,HttpServletRequest request, HttpServletResponse response, Model model) {
		Map<String,Object> map = AccountCacheHelper.getMap(account.getUserId() + "_" + account.getId());
		System.out.println(map);
		if (StringUtils.isNotBlank(account.getUsedFlag())) {
			String value = AccountCacheHelper.getStringValue(account.getUserId() + "_" + account.getId(), account.getUsedFlag(), "");
			System.out.println(value);
		}
		return "index";
	}

	@RequestMapping(value = "/getaway")
	public String getaway(SmsGateway smsGateway, HttpServletRequest request, HttpServletResponse response, Model model) {
		/*GateWayHttpAbstract  gateWayHttpAbstract = HttpGatewayFactory.GATEWAY_MAP.get(smsGateway.getGwCode());
		model.addAttribute("gateWayHttpAbstract", gateWayHttpAbstract);
		Map<String, GateWayHttpAbstract>  gatewayMap = HttpGatewayFactory.GATEWAY_MAP;
		model.addAttribute("gatewayMap", gatewayMap);
		SmsGateway gateway= GatewayCacheHelper.get(smsGateway.getGwCode());
		model.addAttribute("gateway", gateway);*/
		Map<String, Object> map = Maps.newHashMap();
		map.put("phone","18268846802");
		map.put("tableName","sms_send_1");
		map.put("orderby","create_time");
		List<SmsSend> list = smsSendService.findPageByPhone(map);
		for (SmsSend smsSend:list) {
			System.out.println("号码：" + smsSend.getPhone() + ",id:" + smsSend.getId());
		}
		return "/smsGateway/index";
	}
}